<template>
	<view class="tag-list">
		<block v-for="(item,index) in list">
			<g-img :list="item"></g-img>
		</block>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:null,
				tag:null,
				total:null,
				skipL:10
			}
		},
		onLoad(e) {
			this.tag = e.tag
			this.getCount()
		},
		methods: {
			// 瀑布流
			getCount(){
				const db = uniCloud.database();
				db.collection('bz-list').where({
					"img.tag":this.tag
				}).count()
				.then(res=>{
					console.log(res.result.total,'记录')
					this.total = res.result.total
					this.getList()
				})
			},
			getList(){
				const db = uniCloud.database();
				const dbCmd = db.command
				console.log(this.tag,'fenlei')
				db.collection('bz-list').where({
					"img.tag":this.tag
				}).orderBy("img.sjc", "desc").limit(10).get()
				.then(res=>{
					console.log(res.result.data,'jmain')
					this.list = res.result.data
				})
			}
		},
		onReachBottom() {
			if(this.skipL>this.total){
				uni.showToast({
					icon:'none',
					title:'已加载完成'
				})
			}else{
				const db = uniCloud.database();
				db.collection('bz-list').where({
					"img.tag":this.tag
				}).skip(this.skipL).orderBy("img.sjc", "desc").limit(10).get()
				.then(res=>{
					console.log(res.result.data,'count')
					this.skipL =this.skipL+10
					console.log('页数',this.skipL)
					const arr = res.result.data
					const brr = this.list
					this.list = brr.concat(arr)
					console.log(this.list,'zuixin')
				})
			}
		}
	}
</script>

<style lang="scss">
		.tag-list{
			display: flex;
			justify-content: space-around;
			flex-wrap: wrap;
		}
</style>
